home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -in_the_mag- / multitasking / coders / ppipc / broker / read_me < prev    next >
Text File  |  2000-03-05  |  10KB  |  187 lines

  1.  
  2. The programs in this directory are mostly to demonstrate the IPC "Port
  3. Broker" mechanism, in a so far somewhat rudimentary form.
  4.  
  5.     The "Broker" icon starts up the simple Port Broker needed for the demo.
  6.     To terminate it, type ctrl-C to the window that appears when it's
  7.     running. (Unlike the other icons in this package, this is a Tool, not
  8.     an Xicon script.)
  9.  
  10.     The "Demo" icon runs the same programs as "IPC_Demo" in the parent
  11.     directory, but using the Broker.  See below for more details.
  12.  
  13. There is also an IPCPort "Cleaner" program (no icon) -- described at the
  14. end of this text. Sources for both Broker and Cleaner are in the "Sources"
  15. directory.
  16.  
  17.  
  18. IPC Port Broker
  19. ===============
  20.  
  21. The concept of the Port Broker is fairly central to this IPC system, even
  22. though it is itself not really part of the protocol. It is a program that
  23. will normally remain continuously resident while IPC is in use, managing
  24. the loading of programs that provide services to others.
  25.  
  26. Any Client process that wants another (Server) process to perform some task
  27. for it, only needs to know the True Name of the IPCPort to which it should
  28. make its demands.  [I think the Magicians of Old had a similar notion...]
  29. The Client does a LoadIPCPort call with that name, and -- if the port is
  30. not already in service -- the request is passed to the Broker.  The Broker
  31. will previously have been informed of the exact Secret Words [CLI Command]
  32. needed to invoke the Servant of the Port, and will at once perform the
  33. necessary deeds.
  34.  
  35. The advantages of this scheme are twofold: first, processes get started up
  36. automatically when needed (and can terminate themselves when they decide
  37. their usefulness is over); second, the user can configure his system with
  38. his own choice of servers, as long as the name of a port that provides a
  39. certain function is standardised.
  40.  
  41.                             + + +
  42.  
  43. The demo in this directory is a very simple example of the concept.  It
  44. also neatly shows some of the problems with Simplicity...
  45.  
  46. For the demo to work, you must have started the Broker first, by clicking
  47. on its icon.  Though you will see that this version of the broker has its
  48. own window (courtesy of Lattice) no output will appear there.  Its only
  49. usefulness is to let you terminate the program again by typing ctrl-C
  50. to it.  This is one of the artefacts of Simplicity.
  51.  
  52. By the way, if you want to see what happens if you try the demo without the
  53. broker running, go ahead.  The results pose no hazard to your system's
  54. health (and should be self-explanatory).
  55.  
  56. You'll find that the Broker demo uses exactly the same (stupid) Client and
  57. Server as the "IPC_Demo" in the parent directory (which therefore must
  58. remain available for anything at all to work).  However, unlike the latter,
  59. it starts only the Client from the icon script, and not the Server.
  60.  
  61. The first thing the Client does is request a 'LoadIPCPort("Print_Format")'
  62. (that's the name of the IPCPort involved); if there is no Server for the
  63. port already running, a message is whipped off to the Broker, which looks
  64. that name up in its list (a short one in this case!).  That list, by the
  65. way, is loaded from the file "port_list" in this directory (more on this
  66. later).  Corresponding to that name, it finds the command needed to start
  67. the Server (from the directory "/IPC_Demo"), and fires it up.
  68.  
  69. Another consequence of Simplicity unfortunately pops up right here.  All
  70. input and output for these programs is done (Simply) by redirecting
  71. standard input and output to console windows.  Each window is in turn
  72. created Active, so the last one created is the one that ends up Active.
  73. And of course this is the Server output -- not the Client input, as we
  74. would like.  The non-broker form of this demo avoids the difficulty just by
  75. starting the Server first, but of course that doesn't work here.  There are
  76. lots of ways we could rewrite the programs to avoid this, but on the other
  77. hand it's probably a good idea to present some of the problem areas too...
  78.  
  79. If you like, you can try activating a second instance of the demo.  This
  80. time the Server is already running, so the Client is able to get to it
  81. immediately (and the Server naturally has no problem handling more than one
  82. Client).  This means of course that this time we avoid the problem just
  83. mentioned.  (You can also run multiple copies of IPC_Demo, but the results
  84. are not as clean there because the script tries -- and fails -- to start up
  85. a new Server each time.)
  86.  
  87. I should point out in passing that the Client start-up code was specially
  88. written to work with or without a Broker.  This is easy to do, but in the
  89. normal case probably wouldn't be desirable.
  90.  
  91.  
  92.  
  93.     *************************************************************
  94.  
  95. The Broker Code
  96. ===============
  97.  
  98. The Broker program obtains the names of IPCPorts it may have to load, and
  99. the CLI commands it will need to load them, from a file it reads when it is
  100. started.  The name of this file may be specified in ToolType "FILE=name" of
  101. the icon if it is started from the WorkBench, or as a command line argument
  102. if it is run from the CLI.  If no file is specified it will look for
  103. "S:IPC_Port_List".  If it can't read a file, or the file is empty, it will
  104. abort.  Otherwise it remains resident (mostly in a Wait state) until
  105. terminated by a ctrl-C break.
  106.  
  107. As this is only a simple implementation, it just reads the file at start
  108. up.  A more complete one will doubtless have ways of adding or changing
  109. entries in the list at a later time.
  110.  
  111. The Broker is sent a message whenever a LoadIPCPort call in another program
  112. cannot find a served port of the specified name already active.  The broker
  113. looks the name up in its list (a linear search -- probably quite adequate
  114. here); if it is found, there will be a CLI command associated with it --
  115. to start the Server --, which the broker executes. At the same time, the
  116. port is marked as "LOADING", so that it can accept messages.
  117.  
  118. The file format is simply a series of single-line entries, each beginning
  119. with a port name ENCLOSED IN (double) QUOTES, followed by a space and then
  120. the CLI command to be executed.  (A full command pathname is generally
  121. required -- unless the command is in 'C:'; full paths are always required
  122. for filenames used as arguments.  'ASSIGN'ing a shorthand path -- as done
  123. in the demo -- is a useful dodge here.)  Any line that doesn't begin with a
  124. quote is simply skipped, so you can include comments if you want.
  125.  
  126. This format was chosen simply because it was easy to implement -- other
  127. brokers might define quite a different one.  Multiple line commands, or
  128. wild card matching, might be allowed, for instance.  And as the design
  129. evolves, other sorts of capabilities are sure to be added.  Maybe the
  130. Broker might have a "button panel" for launching Clients too, or for
  131. sending specific messages.  It certainly will need an ARexx interface.  The
  132. reserved IPCPort for the Broker -- "PortBrokerPort" -- is of course
  133. available for any other categories of message you might want to send to the
  134. program.  Just avoid using the 'IPPL' message ID that LoaIPCPort transmits
  135. (unless it's appropriate!).
  136.  
  137. Note that -- because of Execute()'s limitations -- there is no way for the
  138. broker to know if the command has actually been successfully launched or
  139. not.  So it is possible that a "LOADING" port might fail in fact to do so!
  140. There are ways for a Brighter Broker to handle this: one simple way is to
  141. send a dummy message to the loading port; if this isn't replied within a
  142. certain time, it can assume the load has failed, in which case it Serves
  143. the port itself, bounces back any pending messages with an error code, and
  144. lets it go.
  145.  
  146. Note also that -- for similar reasons -- any text output resulting
  147. from a command is directed to NIL: when the broker is started from an icon.
  148. It should be possible to direct it to the window Lattice kindly opens for
  149. us, but this is not straightforward.  Actually you probably don't really
  150. want any command output, but if you do you can always 'RUN' it from a CLI.
  151.  
  152.     *************************************************************
  153.  
  154.  
  155. Cleaner
  156. =======
  157.  
  158. This is a small utility program to help you keep tabs on things when you're
  159. experimenting with IPCPorts.  It combines two different functions into one
  160. package, depending on whether you give it any command line arguments or
  161. not. (It can only be run from the CLI.)
  162.  
  163. Invoked without any arguments, it prints a list of all the IPCPorts
  164. currently defined, with the number of references (Clients or Servers) to
  165. each, and any state flags set.
  166.  
  167. If you give the name of any currently valid IPCPort as an argument
  168. (multiple items allowed) it will remove ALL the references to that port,
  169. and the port itself. This is intended as an "Emergency Recovery" operation
  170. only!!
  171.  
  172. If IPC programs are correctly written, they shouldn't leave excess port
  173. references around when they leave, and if they're still running you should
  174. NEVER remove a port from under them.  However, it's easy to forget
  175. something while you're developing code, and to leave a reference that stays
  176. around for ever; if this is a Server, you're really in trouble because no
  177. other Server can then attach to the port.
  178.  
  179. If you suspect something of this sort has happened, you can check by using
  180. Cleaner with no arguments. If you do find it to be the case, then clear up
  181. the problem by invoking Cleaner with the name of the hung port as argument.
  182. Of course, all processes CORRECTLY connected to the port should be
  183. terminated before using this command.
  184.  
  185.     **************************************************************
  186.  
  187.